Summary of Python Encryption Method [md5 base64 sha1]
- 2020-06-12 09:50:46
- OfStack
The python encryption method is summarized in this paper. To share for your reference, specific as follows:
MD5 encryption:
def md5(str):
import hashlib
m = hashlib.md5()
m.update(str)
return m.hexdigest()
base64 encryption:
import base64
s = ' I'm a string '
a = base64.b64encode(s)
print a
print base64.b64decode(a)
Output results:
ztLKx9fWt/u0rg==
I'm a string
sha1 encryption:
The hashlib module needs to be imported:
import hashlib
def str_encrypt(str):
"""
use sha1 Encryption algorithm, return str Encrypted string
"""
sha = hashlib.sha1(str)
encrypts = sha.hexdigest()
return encrypts
PS: About encryption and decryption interested friends can also refer to this online tools:
Text online encryption and decryption tools (including AES, DES, RC4, etc.) :
http://tools.ofstack.com/password/txt_encode
MD5 Online encryption Tools:
http://tools.ofstack.com/password/CreateMD5Password
Online hashing/hashing algorithm encryption tools:
http://tools.ofstack.com/password/hash_encrypt
Online MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 Encryption tools:
http://tools.ofstack.com/password/hash_md5_sha
Online sha1 sha224 / sha256 sha384 / sha512 encryption tools:
http://tools.ofstack.com/password/sha_encode
For more information about Python, please refer to: Python Encryption and decryption algorithm and techniques summary, Python Coding skills Summary, Python Data Structure and Algorithm Tutorial, Python Function Using Techniques Summary, Python String Manipulation Techniques Summary and Python Introduction and Advanced Classic Tutorial.
I hope this article has been helpful in Python programming.